<template>
	<view>
		<view class="walletItem">
			<view>编辑信息</view>
			<input placeholder="请输入银行卡号" v-model="bank.bank_num" />
			<input placeholder="请输入开户行 如:中国银行" v-model="bank.bank_name" />
			<input placeholder="请输入开户行支行 如:北京市分行人民路支行" v-model="bank.bank_branch" />
			<input placeholder="请输入开户人姓名" v-model="bank.account" />
			<!-- <view class="setDefault flex align-center justify-between">
				<text>设为默认</text>
				<switch @change="setDefault" :class="bank.defaultFlag == '1'?'checked':''" color="#39B54A"></switch>
			</view> -->
		</view>
		<button class="buyBtn" @click="subBank">保存</button>
	</view>
</template>

<script>
	import {
		post,
		get
	} from "@/utils/post.js";
	export default {
		data() {
			return {
				bank: {
					"bankId": "",
					"bank_name": "",
					"bank_num": "",
					"defaultFlag": "",
					"bank_branch": "",
					"account": ""
				}
			}
		},
		onLoad(op) {
			if(op.id){
				this.id = op.id
				this.getdetail()
			}
		},
		methods: {
			getdetail(){
				this.$sloading()
				this.$request({
					url: this.$api.wallet.bank_info,
					method:'post',
					data: {
						id:this.id
					}
				}).then(info => {
					this.$hloading()
					if (info.code == 0) {
						Object.assign(this.bank,info.data)
					}
				}).catch(info => {
					this.$hloading()
				})
			},
			setDefault(e) {
				this.bank.defaultFlag = e.detail.value?'1':'0'
			},
			subBank() {
				if (!this.bank.account) {
					this.$showM('请输入开户人姓名', false)
					return
				}
				if (!this.bank.bank_num) {
					this.$showM('请输入银行卡号', false)
					return
				}
				if (!this.bank.bank_name) {
					this.$showM('请输入银行名称', false)
					return
				}
				if (!this.bank.bank_branch) {
					this.$showM('请输入开户行支行', false)
					return
				}
				this.$sloading()
				this.$request({
					url: this.$api.wallet.edit_bank,
					method:'post',
					data: {
						type:1,
						account:this.bank.account,
						bank_branch:this.bank.bank_branch,
						bank_num:this.bank.bank_num,
						bank_name:this.bank.bank_name,
						id:this.id
					}
				}).then(info => {
					this.$hloading()
					if (info.code == 0) {
						this.$showM('保存成功', false, r => {
							uni.navigateBack()
						})
					}
				}).catch(info => {
					this.$hloading()
				})
			}
		}
	}
</script>

<style scoped lang="less">
	.buyBtn {
		width: 660upx;
		height: 70upx;
		font-size: 30upx;
		line-height: 70upx;
		margin-top: 100upx;
		background-image: linear-gradient(to right,#ffd171,#ff8959);
		color: #fff;
	}

	.setDefault {
		margin-top: 30upx;
	}

	switch {
		transform: scale(0.7);

	}

	.walletItem input {
		width: 100%;
		height: 80upx;
		line-height: 80upx;
		padding: 0 20upx;
		font-size: 28upx;
		border: 1px solid #ccc;
		margin-top: 30upx;
	}

	.walletItem {
		width: 700upx;
		padding: 20upx;
		border-radius: 10upx;
		box-shadow: 0 0 5px #93cdfe;
		background: #fff;
		margin: 40upx auto 0;
	}

	.rightLogo {
		width: 50upx;
		height: 50upx;
	}
</style>
